package com.crrc.dataparse.templatepara.datatrans.utils;

import java.util.HashMap;

public class DataTranslator {
    public DataTranslator() {
    }

    public static String BinToHex(String inStrBin) {
        StringBuilder sb = new StringBuilder();
        int length = inStrBin.length();
        int i;
        if (length % 8 != 0) {
            i = (length / 8 + 1) * 8;
            inStrBin = autoGenericCode(inStrBin, i);
        }

        for(i = 0; i < inStrBin.length(); i += 4) {
            String var4 = inStrBin.substring(i, i + 4);
            byte var5 = -1;
            switch(var4.hashCode()) {
                case 1477632:
                    if (var4.equals("0000")) {
                        var5 = 0;
                    }
                    break;
                case 1477633:
                    if (var4.equals("0001")) {
                        var5 = 1;
                    }
                    break;
                case 1477663:
                    if (var4.equals("0010")) {
                        var5 = 2;
                    }
                    break;
                case 1477664:
                    if (var4.equals("0011")) {
                        var5 = 3;
                    }
                    break;
                case 1478593:
                    if (var4.equals("0100")) {
                        var5 = 4;
                    }
                    break;
                case 1478594:
                    if (var4.equals("0101")) {
                        var5 = 5;
                    }
                    break;
                case 1478624:
                    if (var4.equals("0110")) {
                        var5 = 6;
                    }
                    break;
                case 1478625:
                    if (var4.equals("0111")) {
                        var5 = 7;
                    }
                    break;
                case 1507423:
                    if (var4.equals("1000")) {
                        var5 = 8;
                    }
                    break;
                case 1507424:
                    if (var4.equals("1001")) {
                        var5 = 9;
                    }
                    break;
                case 1507454:
                    if (var4.equals("1010")) {
                        var5 = 10;
                    }
                    break;
                case 1507455:
                    if (var4.equals("1011")) {
                        var5 = 11;
                    }
                    break;
                case 1508384:
                    if (var4.equals("1100")) {
                        var5 = 12;
                    }
                    break;
                case 1508385:
                    if (var4.equals("1101")) {
                        var5 = 13;
                    }
                    break;
                case 1508415:
                    if (var4.equals("1110")) {
                        var5 = 14;
                    }
                    break;
                case 1508416:
                    if (var4.equals("1111")) {
                        var5 = 15;
                    }
            }

            switch(var5) {
                case 0:
                    sb.append("0");
                    break;
                case 1:
                    sb.append("1");
                    break;
                case 2:
                    sb.append("2");
                    break;
                case 3:
                    sb.append("3");
                    break;
                case 4:
                    sb.append("4");
                    break;
                case 5:
                    sb.append("5");
                    break;
                case 6:
                    sb.append("6");
                    break;
                case 7:
                    sb.append("7");
                    break;
                case 8:
                    sb.append("8");
                    break;
                case 9:
                    sb.append("9");
                    break;
                case 10:
                    sb.append("A");
                    break;
                case 11:
                    sb.append("B");
                    break;
                case 12:
                    sb.append("C");
                    break;
                case 13:
                    sb.append("D");
                    break;
                case 14:
                    sb.append("E");
                    break;
                case 15:
                    sb.append("F");
                    break;
                default:
                    return sb.toString();
            }
        }

        return sb.toString();
    }

    private static String autoGenericCode(String code, int num) {
        int length = code.length();

        for(int i = 0; i < num - length; ++i) {
            code = "0" + code;
        }

        return code;
    }

    public static HashMap<String, String> extraParamsMap(String extraParams) {
        String pureStr = extraParams.toLowerCase().replaceAll("\"", "").replaceAll("\\{", "").replaceAll("}", "");
        HashMap<String, String> jsonMap = new HashMap();
        String[] KVs = pureStr.split(",");
        String[] var4 = KVs;
        int var5 = KVs.length;

        for(int var6 = 0; var6 < var5; ++var6) {
            String KV = var4[var6];
            String[] K_V = KV.split(":");
            if (K_V.length == 1) {
                K_V[1] = "";
            }

            jsonMap.put(K_V[0], K_V[1]);
        }

        return jsonMap;
    }

    public static final boolean isValid(String value) {
        return value.length() != 0;
    }
}